package com.giw.project.graph;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.giw.project.exception_manager.UncheckedException;

public class GraphGeneratorMapper extends Mapper<LongWritable, Text, Text, Text>{

	protected void map(LongWritable key, Text value, Context context)
	throws IOException, InterruptedException{

		String line=value.toString();
		String[] parts=line.split(" ");
		String node=parts[0];
		String link=parts[1];
		String neighbour=line.substring(node.length()+link.length()+2,line.length()-2);
		String mapValue="{"+link+","+neighbour+"}";
		try{
			context.write(new Text(node), new Text(mapValue));
			mapValue="{"+link+","+node+"}";
			context.write(new Text(neighbour), new Text(mapValue));
		}
		catch(IOException e){
			throw new UncheckedException("Error while trying the map operation.\nMeesage:"+e.getMessage());
		}
		catch(InterruptedException e){
			throw new UncheckedException("Error while trying the map operation.\nMeesage:"+e.getMessage());
		}



	}
}
